package org.dfl.taverna;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Properties;

import org.dfl.log.Logger;
import org.dfl.plugin.DflPlugin;

/**
 *
 * @author Lukas
 */
public class Configuration {

    private static Configuration instance = null;
    private String[] defaultBiomoby;
    private String[] defaultWSDL;
    private String[] defaultMartRegistry;
    private String[] defaultSoaplab;

    private static String[] split(String string) {
        return string.split("\\s*,\\s*");
    }
    
    private InputStream getResource(String name) throws IOException {
    	URL url = DflPlugin.getURLFromPlugin(name);
    	return url.openStream();
    }

    private Configuration() {
        try {
            Properties props = new Properties();
            props.load(getResource("conf/mygrid.properties"));
            System.getProperties().putAll(props);
        } catch (IOException ex) {
            Logger.logException(ex);
        }

        defaultBiomoby = split(System.getProperty("taverna.defaultbiomoby"));
        defaultWSDL = split(System.getProperty("taverna.defaultwsdl"));
        defaultMartRegistry = split(System.getProperty("taverna.defaultmartregistry"));
        defaultSoaplab = split(System.getProperty("taverna.defaultsoaplab"));
    }

    public static Configuration getInstance() {
        if (instance == null) {
            instance = new Configuration();
        }

        return instance;
    }

    public String[] getDefaultBiomoby() {
        return defaultBiomoby;
    }

    public String[] getDefaultWSDL() {
        return defaultWSDL;
    }

    public String[] getDefaultMartRegistry() {
        return defaultMartRegistry;
    }

    public String[] getDefaultSoaplab() {
        return defaultSoaplab;
    }
}
